using System;
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;

namespace Ease.EaseNode.Editor.NodeView
{
    public abstract class BaseSearchMenuWindowProvider : ScriptableObject, ISearchWindowProvider
    {
        public event Func<SearchTreeEntry, SearchWindowContext, bool> OnSelectEntryHandler;

        public List<SearchTreeEntry> CreateSearchTree(SearchWindowContext context)
        {
            return DoCreateSearchTree(context);
        }

        public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
        {
            if (OnSelectEntryHandler == null)
            {
                return false;
            }

            return OnSelectEntryHandler(searchTreeEntry, context);
        }

        protected abstract List<SearchTreeEntry> DoCreateSearchTree(SearchWindowContext context);
        
        //Template:
        //protected abstract List<SearchTreeEntry> DoCreateSearchTree(SearchWindowContext context)
        //{
        //var entries = new List<SearchTreeEntry>();
        //entries.Add(new SearchTreeGroupEntry(new GUIContent("名称")));
        //entries.Add(new SearchTreeGroupEntry(new GUIContent("1级菜单")) { level = 1 });
        //entries.Add(new SearchTreeGroupEntry(new GUIContent("2级菜单")) { level = 2 });
        //entries.Add(new SearchTreeGroupEntry(new GUIContent("3级菜单")) { level = 3 });
        //entries.Add(new SearchTreeEntry(new GUIContent("3级菜单选项")) { level = 3, userData = null });
        //return entries;
        //}
    }
}